package com.dgshanger.sanhxiaofeisc.mvp.model

import com.blankj.utilcode.util.EncryptUtils
import com.blankj.utilcode.util.SPUtils
import com.dgshanger.sanhxiaofeisc.common.AppApi
import com.dgshanger.sanhxiaofeisc.common.Constants
import com.dgshanger.sanhxiaofeisc.entity.RegisterEntity
import com.dgshanger.sanhxiaofeisc.mvp.contract.RegisterContract
import com.xx.baseutilslibrary.network.rx.RxHelper
import com.xx.baseutilslibrary.network.rx.XxBaseHttpObserver

/**
 * RegisterModel
 * 沉迷学习不能自拔
 * Describe：
 * Created by 雷小星🍀 on 2018/2/6 9:34.
 */

class RegisterModel : RegisterContract.Model {

    override fun register(mobile: String, verify_code: String, pwd: String, invite_code: String?, httpObserver: XxBaseHttpObserver<RegisterEntity>?) {
        AppApi.Api()
                .register(mobile, verify_code, EncryptUtils.encryptMD5ToString(pwd).toLowerCase(), invite_code)
                .compose(RxHelper.io_main())
                .compose(RxHelper.start_finish(httpObserver))
                .subscribe(httpObserver)
    }

    override fun sendVCode(phone: String, httpObserver: XxBaseHttpObserver<Any>?) {

        AppApi.Api()
                .get_pin(phone, "app_register")
                .compose(RxHelper.io_main())
                .compose(RxHelper.start_finish(httpObserver))
                .subscribe(httpObserver)
    }


    override fun putToken(token: String?) {
        SPUtils.getInstance().put(Constants.KEY_SP_TOKEN, token!!)
    }
}
